import 'package:flutter/material.dart';

class CustomText extends StatelessWidget {
  final TextOverflow? overflow;
  final double? textScaleFactor;
  final int? maxLines;
  final Color? color;
  final String? text;
  final double? fontSize;
  final double? height;
  final double? width;
  final BoxConstraints? constraints;
  final EdgeInsetsGeometry? padding;
  final EdgeInsetsGeometry? margin;
  final Color? bgColor;
  final double? radius;
  final FontWeight? fontWeight;
  final Color? borderColor;
  final double? borderWidth;
  final MainAxisAlignment mainAxisAlignment;
  final CrossAxisAlignment crossAxisAlignment;
  final TextAlign? textAlign;

  const CustomText(
    this.text, {
    super.key,
    this.overflow,
    this.textScaleFactor,
    this.maxLines,
    this.color,
    this.fontSize,
    this.height,
    this.width,
    this.padding,
    this.margin,
    this.bgColor,
    this.radius,
    this.fontWeight,
    this.borderColor,
    this.borderWidth = 0.0,
    this.mainAxisAlignment = MainAxisAlignment.start,
    this.crossAxisAlignment = CrossAxisAlignment.start,
    this.constraints,
    this.textAlign,
  });

  @override
  Widget build(BuildContext context) {
    Widget textWidget = Text(
      text ?? "",
      key: key,
      maxLines: maxLines,
      textAlign: textAlign,
      overflow: overflow,
      style:
          TextStyle(fontSize: fontSize, color: color, fontWeight: fontWeight),
    );

    if (padding != null ||
        height != null ||
        margin != null ||
        borderWidth != null ||
        bgColor != null ||
        constraints != null) {
      textWidget = Container(
        constraints: constraints,
        padding: padding,
        height: height,
        width: width,
        margin: margin,
        decoration: BoxDecoration(
            color: bgColor,
            borderRadius: BorderRadius.circular(radius ?? 0),
            border: Border.all(
                color: borderColor ?? Colors.transparent,
                width: borderWidth ?? 0)),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          mainAxisAlignment: mainAxisAlignment,
          crossAxisAlignment: crossAxisAlignment,
          children: [textWidget],
        ),
      );
    }
    return textWidget;
  }
}
